package org.comeday.idempotent.service;

import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.concurrent.TimeUnit;

/**
 * Program Name: spring_study
 * <p>
 * Description:
 * <p>
 * Created by hkrong on 2024/11/24 17:00
 *
 * @author hkrong
 * @version 1.0
 */
@Component
public class IdempotentStorage {

    @Resource
    private RedisTemplate<String, Serializable> redisTemplate;

    public void save(String idempotentId){
        redisTemplate.opsForValue().set(idempotentId, idempotentId,10, TimeUnit.SECONDS);
    }

    public boolean delete(String idempotentId) {
        return redisTemplate.delete(idempotentId);
    }
}
